package com.tacademy.jmtwitter;

import java.net.URL;
import java.util.ArrayList;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.EditText;
import android.widget.ListView;

public class SearchFriendActivity extends Activity{
	ArrayList<Status> mDataList;
	ListView mList;
	TimelineAdapter mAdapter;
	EditText mEdit;
	static String mScreenName;
	SuchFriend mTask;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_searchfriend);
		mScreenName = "01055261297";
		mList = (ListView)findViewById(R.id.friendListView);
		mTask = new SuchFriend();
		mTask.execute();
	}
	
	class SuchFriend extends AsyncTask<URL, Integer, Long> {

		@Override
		protected Long doInBackground(URL... params) {
			SharedPreferences pref = getSharedPreferences(Authorize.SAVE,
					MODE_PRIVATE);
			
			
			Log.d("Notification", "run");
			mDataList = new TwitterApi(
					pref.getString(Authorize.TOKEN, null), pref.getString(
							Authorize.SECRET, null)).getUserTimeline(mScreenName, 20, 0, 0);			
			return null;
			
		}

		@Override
		protected void onPreExecute() {
			// doInBackground 전에 excute를 호출한 thread에서 실행
			super.onPreExecute();
		}

		@Override
		protected void onPostExecute(Long result) {
			// doInBackground 실행뒤 main에서 실행
			mAdapter = new TimelineAdapter(SearchFriendActivity.this,
					mDataList);
			mList.setAdapter(mAdapter);
			mAdapter.notifyDataSetChanged();
			super.onPostExecute(result);
			

		}

		@Override
		protected void onProgressUpdate(Integer... values) {
			super.onProgressUpdate(values);
			switch (values[0]) {
			case 1:
				// mProgress.setVisibility(View.INVISIBLE);
				
				break;
			case 2:
				
				break;
			default:
				break;
			}

			// // values[0];
			// values.length;
		}
	}

}
